#! /bin/sh

pathname=`pwd`
pathname=$(basename $pathname)
header=$pathname'.h'

function e(){
#echo $1
    for file in `ls $1`
    do
        if [ -d $1$file ]
        then
            e $1$file
        else
            if [[ $file == *.h ]]
            then
                echo "#import \"$file\"" >> $header
            fi
        fi
    done
}

function f(){
    echo "    #if __has_include(<$1.h>)" >> $header
    echo "        #import <$1.h>" >> $header
    echo "    #elif __has_include(\"$1.h\")" >> $header
    echo "        #import \"$1.h\"" >> $header
    echo "    #endif" >> $header
    echo "" >> $header
}


sed -i '' '1,$d' $header
echo "//" >> $header
echo "//  $header" >> $header
echo "//  $pathname" >> $header
echo "//" >> $header
echo "//  Created by 李双鹏 on 15/10/04." >> $header
echo "//  Copyright (c) 2015 LSP. All rights reserved." >> $header
echo "//" >> $header
echo "" >> $header
echo "" >> $header
echo "#ifdef __OBJC__" >> $header
echo "" >> $header
#echo '/* 1.select the project file -> 2.select the 'Bulid Settings' tab ->' >> $header
#echo '   3.search 'linker' -> 4.double click 'Other Linker Flags' ->' >> $header
#echo '   5.add a line and type '-ObjC'.(Case Sensitive) case sensitive*/' >> $header

for file in `ls`
do
    if [ -d $1$file ]
    then

        echo "s.subspec '$file' do |ss|"
        echo "   # ss.dependency 'PodName'"
        echo "    ss.source_files = '$pathname/$file/*.{h,m}'"
        echo "    ss.public_header_files = '$pathname/$file/*.h'"
        echo "   # ss.frameworks = 'SystemConfiguration', 'UIKit'"
        echo "end"
        echo ""

        e $1$file
    else
        if [[ $file == *.h && $file != $header ]]
        then
            echo "#import \"$file\"" >> $header
        fi
    fi
done

echo "" >> $header
echo "" >> $header



#for file in ../*.podspec
#do
#    for depend in `cat $file | grep "\ s.dependency" | awk -F "'" '{ print $2 }'`
#    do
#        f $depend
#    done
#
#done

echo "" >> $header
echo "" >> $header
echo "#endif" >> $header
echo "" >> $header
